package com.itheima.dao;

import com.github.pagehelper.Page;
import com.itheima.pojo.Menu;
import com.itheima.pojo.Role;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.common.BaseMapper;

import java.util.List;
import java.util.Set;

/**
 * @Author: bowen
 * @Date: 2019/7/22 15:35
 * @Description:
 */
public interface RoleDao extends BaseMapper<Role> {

	Set<Role> findRolesByUserId(Integer id);

	@Select("select * from t_role")
	Page<Role> findPage();

	@Select("select * from t_role where id = #{id}")
	Role findRoleByID(Integer id);

	void addRole(Role role);

	void edit(Role role);

	@Select("select * from t_role")
	List<Role> findAll();

	void addRoleAndPermissionIds(Integer id, Integer[] permissionIds);

	void addRoleAndMenuIds(Integer[] menuIds);

	@Select("delete from t_role_permission where role_id = #{id}")
	void deletePermission(Integer id);

	@Select("delete from t_role_menu where role_id = #{id}")
	void deleteMenuIds(Integer id);

	@Select(" select menu_id from t_role_menu where role_id = #{id}")
    Integer[] findMenuById(Integer id);

	@Select(" select permission_id from t_role_permission where role_id = #{id}")
    Integer[] findPermissionById(Integer id);
}
